package 工具函数模板;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;

public class CLZ银行问题 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();

        ArrayList<String> arrayList = new ArrayList<>();

        for (int i = 0; i <= n; i++) {
            arrayList.add(scanner.nextLine());
        }

        LinkedList<String> vip = new LinkedList<>();
        LinkedList<String> NO = new LinkedList<>();

        for (String s : arrayList) {
            String[] strings = s.split(" ");
            if (strings[0].equals("IN") && strings[2].equals("N")) {
                NO.addLast(strings[1]);
            } else if (strings[0].equals("IN") && strings[2].equals("V")) {
                vip.addLast(strings[1]);
            } else if (strings[0].equals("OUT") && strings[1].equals("N")) {
                NO.pop();
            } else if (strings[0].equals("OUT") && strings[1].equals("v")) {
                vip.pop();
            }
        }
        for (String s : vip) {
            System.out.println(s);
        }

        for (String s : NO) {
            System.out.println(s);
        }

    }
}
